<template>
  <div class="danye">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>活动管理</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="mar-top">
      <el-button
        style="margin-right: 1rem"
        type="primary"
        @click="showAddDialog"
        >添加活动酒品</el-button
      >
      <el-input
        v-model="searchKeyword"
        placeholder="请输入搜索商品"
        style="width: 200px; margin-bottom: 10px"
        clearable
      >
        <el-button
          slot="append"
          icon="el-icon-search"
          @click="handleSearch"
        ></el-button>
      </el-input>
    </div>
    <el-table :data="wineList" border style="width: 100%">
      <el-table-column label="活动" prop="name"></el-table-column>
      <el-table-column label="商品" prop="w_name"></el-table-column>
      <el-table-column label="图片" prop="image_url">
        <template slot-scope="scope">
          <el-image
            style="width: 50px; height: 50px"
            :src="scope.row.image_url.split(',')[0]"
            :preview-src-list="[scope.row.image_url.split(',')[0]]"
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="类型" prop="type"></el-table-column>
      <el-table-column label="产地" prop="origin"></el-table-column>
      <el-table-column label="年份" prop="vintage_year"></el-table-column>
      <el-table-column
        label="酒精含量"
        prop="alcohol_content"
      ></el-table-column>
      <el-table-column label="价格" prop="price"></el-table-column>
      <el-table-column label="库存" prop="stock_quantity"></el-table-column>
      <el-table-column label="开始日期" prop="start_date"></el-table-column>
      <el-table-column label="结束日期" prop="end_date"></el-table-column>
      <el-table-column label="折扣" prop="discount_percent"></el-table-column>
      <el-table-column label="描述" prop="description"></el-table-column>
      <el-table-column label="创建时间" prop="created_at"></el-table-column>
      <el-table-column label="更新时间" prop="updated_at"></el-table-column>
      <!-- 其他需要展示的字段根据实际情况添加 -->
      <el-table-column label="操作" fixed="right" width="150">
        <template slot-scope="scope">
          <el-button size="mini" @click="editWi(scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="deleteWine(scope.row)"
            >删除</el-button
          >
        </template></el-table-column
      >
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="current"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    />
  </div>
</template>

<script>
import { wineCList, deleteWine } from "@/api/winepromotion";
import { Message } from "element-ui";
export default {
  data() {
    return {
      mode: "",
      wineList: [],
      size: 10,
      current: 1,
      total: 0,searchKeyword:''
    };
  },
  methods: {
    handleSizeChange(val) {
      this.current = val;
    },
    handleCurrentChange(val) {
      this.size = val;
    },
   async deleteWine(val){
    console.log(val);
    const param={
      promotionId:val.promotion_id,
      wineId:val.wine_id
    }
      const res=await deleteWine(param);
      if (res.code == 200) {
        Message(res.message);
        this.loadList();
      } else {
        Message(res.message);
      }
    },
    editWi(e) {
      this.mode = "edite";
      console.log(e);
      this.$router.push({
        name: "activedite",
        params: { wineList: { ...e }, mode: this.mode },
      });
    },
    showAddDialog() {
      this.mode = "add";
      this.$router.push({  name: "activeadd", params: { mode: this.mode } });
    },
    async loadList(searchKeyword) {
      const res = await wineCList(searchKeyword);
      if (res.code == 200) {
        this.wineList = res.data.list.records;
        this.size = res.data.list.size;
        this.total = res.data.list.total;
        this.current=res.data.list.current;
      }
    },
    handleSearch(){
      this.loadList(this.searchKeyword)
    }
  },
  created() {
    this.loadList();
  },
};
</script>

<style>
/* 添加样式以美化页面 */
</style>
